package com.zmm.util.document.register;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

/**
 * 指定扫描的包及类型
 * @author 900045
 * @description:
 * @name IdoRegistry
 * @date By 2021-10-26 15:13:43
 */
public class IdoRegistry implements ImportBeanDefinitionRegistrar {


	private Logger logger       = LoggerFactory.getLogger(this.getClass());

	/**   要扫描的包  */
	private static final String PACKAGE_AUTH = "com.zmm.util.document.code";

	@Override
	public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
		logger.info("ido scan: {}", PACKAGE_AUTH);
		ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, false);
		//扫描 @Component  注解的类
		scanner.addIncludeFilter(new AnnotationTypeFilter(Component.class, false));
		scanner.addIncludeFilter(new AnnotationTypeFilter(RestController.class, false));
		scanner.addIncludeFilter(new AnnotationTypeFilter(Service.class, false));
		scanner.scan(PACKAGE_AUTH);
	}
}
